import type {StoreInterface} from "@/typings/store";
import {getAuthToken} from "@utils/common/Custom";

/**
 * index 功能
 * @date 2023/10/3
 */
export const useUserStore = defineStore(
  "user-store",
  () => {
    const userInfo = ref<StoreInterface.UserInfo>({
      userName: "shareloke",
      password: "12345678",
      lockBgImageUrl: "images/bg/desktop/bg1.jpg",
      avatar: "images/user/user_avatar.png",
      token: "",
    });

    const setToken = () => {
      userInfo.value.token = getAuthToken();
    };

    const removeToken = () => {
      userInfo.value.token = "";
    };
    return {
      ...toRefs(userInfo.value),
      setToken,
      removeToken,
    };
  },
  { persist: true },
);
